package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.lkt.common.util.Query;
import io.lkt.common.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.WantedUsersEntity;
import io.lkt.modules.sys.service.WantedUsersService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 全网通缉用户名单
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2021-01-20 11:44:02
 */
@RestController
@RequestMapping("/sys/wantedusers")
public class WantedUsersController {
    @Autowired
    private WantedUsersService wantedUsersService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sys:wantedusers:list")
    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = wantedUsersService.queryPage(params);

        Query query = new Query(params);
        List<WantedUsersEntity> list = wantedUsersService.queryList(query);

        Integer total = wantedUsersService.queryTotal(query);

        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:wantedusers:info")
    public R info(@PathVariable("id") Integer id){
        WantedUsersEntity wantedUsers = wantedUsersService.queryById(id);

        return R.ok().put("wantedUsers", wantedUsers);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:wantedusers:save")
    public R save(@RequestBody WantedUsersEntity wantedUsers){
        wantedUsersService.creatWanted(wantedUsers);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:wantedusers:update")
    public R update(@RequestBody WantedUsersEntity wantedUsers){
        ValidatorUtils.validateEntity(wantedUsers);
        wantedUsersService.updateWanted(wantedUsers);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:wantedusers:delete")
    public R delete(@RequestBody Integer[] ids){
        wantedUsersService.deleteWantedByIds(Arrays.asList(ids));

        return R.ok();
    }

}
